package codelifes.clms.ui;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.swtdesigner.SWTResourceManager;

public class LoginDialog extends Dialog {

    private Text usernameText;
    private Text passwordText;

    /**
     * Create the dialog.
     * 
     * @param parentShell
     */
    public LoginDialog(Shell parentShell) {
        super(parentShell);
        setShellStyle(SWT.DIALOG_TRIM);
    }

    /**
     * Create contents of the dialog.
     * 
     * @param parent
     */
    @Override
    protected Control createDialogArea(Composite parent) {
        Composite container = (Composite) super.createDialogArea(parent);
        container.setLayout(new GridLayout(3, false));
        new Label(container, SWT.NONE);
        new Label(container, SWT.NONE);
        new Label(container, SWT.NONE);
        new Label(container, SWT.NONE);

        CLabel label = new CLabel(container, SWT.NONE);
        label.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
        label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        label.setText("用户帐号:");

        usernameText = new Text(container, SWT.BORDER);
        usernameText.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
        GridData gd_usernameText = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
        gd_usernameText.widthHint = 180;
        usernameText.setLayoutData(gd_usernameText);
        new Label(container, SWT.NONE);

        CLabel label_1 = new CLabel(container, SWT.NONE);
        label_1.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
        label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        label_1.setText("用户密码:");

        passwordText = new Text(container, SWT.BORDER | SWT.PASSWORD);
        passwordText.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
        GridData gd_passwordText = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
        gd_passwordText.widthHint = 180;
        passwordText.setLayoutData(gd_passwordText);

        return container;
    }

    /**
     * Create contents of the button bar.
     * 
     * @param parent
     */
    @Override
    protected void createButtonsForButtonBar(Composite parent) {
        Button button = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
        button.setFont(SWTResourceManager.getFont("微软雅黑", 8, SWT.NORMAL));
        Button button_1 = createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
        button_1.setFont(SWTResourceManager.getFont("微软雅黑", 8, SWT.NORMAL));
    }

    /**
     * Return the initial size of the dialog.
     */
    @Override
    protected Point getInitialSize() {
        return new Point(350, 180);
    }

}
